﻿using System;
using System.Collections.Generic;
using MugenInjection.Interface;

namespace MugenInjection.Exceptions
{
    /// <summary>
    /// The exception that is thrown when found invalid binding configuration.
    /// </summary>
#if !SILVERLIGHT
#if !NETFX_CORE
    [Serializable]
#endif
#endif
    public class InvalidBindingException : BindingException
    {
        #region Constructor

        /// <summary>
        /// Initializes a new instance of the <see cref="InvalidBindingException"/> class with a specified error message.
        /// </summary>
        /// <param name="binding">The specified <see cref="IBinding"/>.</param>
        /// <param name="message">The message that describes the error.</param>
        public InvalidBindingException(IBinding binding, string message)
            : base(string.Format("Invalid binding configuration for services {0}. Detail: {1}", binding.Services,
                                 message))
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="InvalidBindingException"/> class with a specified error message.
        /// </summary>
        /// <param name="message">The message that describes the error. </param>
        public InvalidBindingException(string message) : base(message)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="InvalidBindingException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
        /// </summary>
        /// <param name="message">The error message that explains the reason for the exception. </param><param name="innerException">The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner exception is specified. </param>
        public InvalidBindingException(string message, Exception innerException) : base(message, innerException)
        {
        }

        #endregion

        #region Method

        internal static InvalidBindingException CreateDuplicateInvalidBindingException(string settingName)
        {
            return new InvalidBindingException(string.Format("Duplication of '{0}' settings. Make sure that when you create a binding, you cannot duplicate the setting.", settingName));
        }

        internal static InvalidBindingException CreateNullInvalidBindingException(string name, string parameterName)
        {
            return
                new InvalidBindingException(
                    string.Format("The {0} is null. Make sure you set '{1}' not equal to null.", name, parameterName),
                    new ArgumentNullException(parameterName));
        }

        #endregion

    }
}